\name{CheckVals}
\alias{CheckVals}
\title{Check whether Data are Valid Values}
\description{This is a utility function that tests whether data are acceptable values returning TRUE only if all data are fine, and informative errors otherwise.
}
\usage{
CheckVals(x, okay, na.rm = TRUE)
}
\arguments{
  \item{x}{The data.  May be a vector, matrix, data frame, list, or array.  Numeric or character or factor data is fine as long as that is what is used fort he "okay" values.
}
  \item{okay}{What values are allowed?  Should be a vector of acceptable responses.}
  \item{na.rm}{Should \code{NA} values be ignored in the checking?  Defaults to \code{TRUE}, if \code{FALSE}, \code{NA} values will generate errors.}
}
\details{Currently all acceptable values must be specified.  Future versions may accept a range.  Because this is meant for strict checking, errors are generated if any data values are not in the \code{okay} set.}
\value{A single \code{TRUE} value if all data values are contained in \code{okay}, otherwise errors with messages indicating which values caused the error.}
\author{Joshua Wiley, \url{http://joshuawiley.com/}}
\note{Hopefully I will expand the notes and details soon.}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, okay, na.rm = TRUE)
{
    cx <- class(x)
    if (!is.vector(x)) {
        if (is.list(x)) {
            x <- unlist(x)
        }
        else if (is.matrix(x) || is.array(x)) {
            x <- as.vector(x)
        }
    }
    if (!is.vector(x))
        stop(cx, " is not a valid class for this function")
    "\%nin\%" <- function(x, table) !.Internal(match(x, table,
        0L, NULL)) > 0L
    if (na.rm)
        okay <- c(okay, NA)
    nm <- x[x \%nin\% okay]
    if (length(nm) > 0)
        stop("\nThe following values are not valid: \n[", paste(nm,
            collapse = ", "), "]")
    return(TRUE)
  }
}
\keyword{utils}
